﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WP09S03_OfficeTracking.Controller;

namespace WP09S03_OfficeTracking
{
    public partial class DiagAddCategory : WP09S03_OfficeTracking.ParentClass.ParentDiag
    {
        public DiagAddCategory()
        {
            InitializeComponent();
            txtID = txtCategoryID.TextBox;
            txtName = txtCategoryName.TextBox;
            txtID.ReadOnly = true;
        }

        private TextBox txtID;
        private TextBox txtName;
     

        private void DiagAddCategory_Load(object sender, EventArgs e)
        {

        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            reset();
        }

        private void reset() {
            txtID.Text = "";
            txtName.Text = "";
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == "") { 
            pErrorProvider.SetError(txtName,"Please enter category name");
            return;
            }

            ItemController ic = new ItemController();


            int id=0;

            bool ret;
                
                try {
                    ret=ic.InsertCategory(ref id,txtName.Text, rbYes.Checked);

                }
            catch(Exception ex){
                CatchError(ex);
                ret = false; 
            }

                if (ret) {

                    SetMessage("Add Successfully!");
                    reset();

                }
                



            
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

  
    }
}
